angular.module('starter')
    .controller('homeCtrl', function($scope, meilvFac,$ionicScrollDelegate) {
        $scope.initHome = function() {
            meilvFac.homepage.index(function(data) {
                $scope.indexInfo = data;
            }, function(data) {
                alert(data.data.info)
            })
        }

        $scope.userCollection = function(id) {
            meilvFac.collection.collectionadd({ article_id: id },
                function(data) {
                    $scope.hasMore=true;
                    $scope.page=0;
                    $scope.articleinfo={};
                    $scope.articleinfo.articleshow=[];
                    $scope.getRecommends();
                },
                function(data) {
                    alert(data.data.info);
                }
            )
        }
        $scope.hasMore=true;
        $scope.page=0;
        $scope.articleinfo={};
        $scope.articleinfo.articleshow=[];
        $scope.getRecommends = function() {
            $scope.page++;
            meilvFac.articleshow.index(
                {
                    article_id:-1,
                    page:$scope.page,
                    limit:2
                },
                function(data) {
                if (data.info && data.info.length) {
                    angular.forEach(data.info, function(s) {
                        $scope.articleinfo.articleshow.push(s);
                    })
                } else {
                    $scope.hasMore = false;
                }
                $scope.$broadcast('scroll.infiniteScrollComplete');
            }, function(data) {
                alert(data);
            });
        }
    })
